package com.shouzheng.yygh.hosp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shouzheng.yygh.common.result.Result;
import com.shouzheng.yygh.hosp.service.HospitalSetService;
import com.shouzheng.yygh.model.hosp.HospitalSet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "医院管理设置")
@RestController
@CrossOrigin
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {

    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "获取医院全部设置")
    @GetMapping("findAll")
    public Result findAllHospitalSet() {
        List<HospitalSet> list = hospitalSetService.list();
        return Result.ok(list);
    }

    @ApiOperation(value = "根据ID获取医院信息")
    @GetMapping("find/{id}")
    public Result findById(@PathVariable Long id) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        return Result.ok(hospitalSet);
    }

    @ApiOperation(value = "分页获取医院信息")
    @GetMapping("findPage/{num}/{size}")
    public Result findPage(@PathVariable("num") Long num, @PathVariable("size") Long size) {

        Page<HospitalSet> page = new Page<>(num, size);

        Page<HospitalSet> hospitalSetPage = hospitalSetService.page(page);
        return Result.ok(hospitalSetPage);
    }

    @ApiOperation(value = "逻辑批量删除医院设置")
    @DeleteMapping("delete")
    public Result deleteBatchHospital(@RequestBody List<Long> ids){

        boolean flag = hospitalSetService.removeByIds(ids);
        if (flag){
            return Result.ok();
        }else{
            return Result.fail();
        }

    }

    @ApiOperation(value = "逻辑删除医院设置")
    @DeleteMapping("delete/{id}")
    public Result deleteHospitalSet(@PathVariable("id") Long id ){

        boolean flag = hospitalSetService.removeById(id);
        if (flag){
            return Result.ok();
        }else{
            return Result.fail();
        }
    }

    @ApiOperation(value = "保存医院设置")
    @PostMapping("save")
    public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet){
        boolean flag = hospitalSetService.save(hospitalSet);
        if (flag){
            return Result.ok();
        }else {
            return Result.fail();
        }

    }

    @ApiOperation(value = "医院锁定/解锁")
    @PutMapping("lockHospitalSet/{id}/{status}")
    public Result lockHospitalSet(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        hospitalSet.setStatus(status);
        boolean flag = hospitalSetService.updateById(hospitalSet);
        if (flag){
            return Result.fail();
        }else{
            return Result.ok();
        }

    }

    @ApiOperation("发送签名")
    @PostMapping("sendSignKey")
    public Result sendSignKey(@RequestBody HospitalSet hospitalSet){

        String signKey = hospitalSet.getSignKey();
        String hoscode = hospitalSet.getHoscode();
        //todo 发送短信

        return Result.ok();

    }

}
